#include <iostream>
using namespace std;

int get_add(int a)
{
    int sum = 0;
    while (a)
    {
        sum += a % 10;
        a /= 10;
    }
    return sum;
}

int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        int a, b, n1, n2;
        bool flag1 = false, flag2 = false;
        cin >> a >> b;
        n1 = get_add(a);
        n2 = get_add(b);
        flag1 = a % n2 == 0;
        flag2 = b % n1 == 0;
        if ((flag1 && flag2) || (!flag1 && !flag2))
        {
            if (a > b)
            {
                cout << "A" << endl;
            }
            else
            {
                cout << "B" << endl;
            }
        }
        else if (flag1)
        {
            cout << "A" << endl;
        }
        else
        {
            cout << "B" << endl;
        }
    }
    return 0;
}